package ar.edu.itba.it.paw.web.transaction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PropertyListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import ar.edu.itba.it.paw.domain.Category;
import ar.edu.itba.it.paw.domain.Product;
import ar.edu.itba.it.paw.domain.Question;
import ar.edu.itba.it.paw.domain.Transaction;
import ar.edu.itba.it.paw.domain.User;
import ar.edu.itba.it.paw.repo.CategoryRepo;
import ar.edu.itba.it.paw.web.MercadoLibre;
import ar.edu.itba.it.paw.web.MercadoLibreSession;
import ar.edu.itba.it.paw.web.base.BasePage;
import ar.edu.itba.it.paw.web.component.TypeLabel;
import ar.edu.itba.it.paw.web.product.EditProductPage;
import ar.edu.itba.it.paw.web.user.UserMenuPage;

public class CountTransactionCategoryPage extends BasePage {

	@SpringBean
	CategoryRepo categoryRepo;
	
	
	
	public CountTransactionCategoryPage(){
		
		
		if(!MercadoLibreSession.get().getUser().isAdmin()){
			setResponsePage(UserMenuPage.class);
			return;
		}
		
		IModel<List<Category>> categoriesModel = new LoadableDetachableModel<List<Category>>() {
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			protected List<Category> load() {
				User user = MercadoLibreSession.get().getUser();
				return categoryRepo.getCategories();
			}
		};
		
		
		add(new PropertyListView<Category>("categories", categoriesModel) {
			
			@Override
			protected void populateItem(ListItem<Category> item) {
				item.add(new Label("name",new PropertyModel<Product>(item.getModel(), "name")).add(new SimpleAttributeModifier("style", "color: #0099FF")));
				item.add(new Label("amount",String.valueOf(item.getModelObject().countTransactions())).add(new SimpleAttributeModifier("style", "")));
			}
		});
		
	}
}
